package com.lovvyang.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author lovvyang
 * @date 2020/6/7-15:50
 */
/*
 * @PackageName:com.lovvyang.request
 * @ClassName:RequestDemo01
 * @Description
 * @author lovvyang
 * @date 2020/6/7/15:50
 **/
@WebServlet("/reqdemo01")
public class RequestDemo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //请求方式
        String method = req.getMethod();
        System.out.println(method);
        //虚拟路径
        String contextPath = req.getContextPath();
        System.out.println(contextPath);
        //资源路径
        String servletPath = req.getServletPath();
        System.out.println(servletPath);
        String h1 = req.getParameter("nihao");
        System.out.println(h1);
        String queryString = req.getQueryString();
        System.out.println(queryString);
        //传输协议
        String protocol = req.getProtocol();
        System.out.println(protocol);
        //相对路径
        String requestURI = req.getRequestURI();
        System.out.println(requestURI);
        //绝对路径
        StringBuffer requestURL = req.getRequestURL();
        System.out.println(requestURL);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
